



<html>

<head>
<LINK href="Style.css" rel=stylesheet> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>Welcome to a page</title>

<script type="text/javascript" language="javascript"> 

function checkIfSure(){
	var isSure = false;
	
		var alert = 'Bạn có chắc chắn xoá thông tin về sinh viên này ?'; 
		
		
		if (confirm(alert)) {
		    isSure = true;
		} 
		else {
		    isSure = false;
		}

	return isSure;
}

</script>
</head>

<body>
  <div id ="mainWap">
  
     <div id ="header">
     <div id ="titlelabel">STUDENT MANAGER</div>
      <ul id="menu">
         <li><a href="index.php">HOME PAGE</a></li>
         <li><a href="insert.php">INSERT</a></li>
         <li><a href="edit.php">EDIT</a></li>
         <li><a href="#">DELETE</a></li>
      </ul>
     </div>
     <div class="clear"></div>
     <div id ="left">
     </div>
     <div id="right">
     
     

<?php      
     
$user = "root";
$password = "";
$database = "SinhVienDatabase";
$connect = mysql_connect("localhost",$user,$password);
mysql_query("set names 'utf8'");
mysql_select_db($database) or die( "Unable to select database");

if (isset($HTTP_POST_VARS["deleteIndex"])) {
   
    $deleteIndex = $HTTP_POST_VARS["deleteIndex"];
    
    $deleteQuery = "Delete from sinhvien where mssv='$deleteIndex'";
    $resultDelete = mysql_query($deleteQuery);
    if ($resultDelete) {
    	echo "<div class='thongbaothanhcong'>Delete succes</div>";
    }
    else{
        echo "<div class='thongbaoloi'>Delete error</div>";
    }
    unset($HTTP_POST_VARS["deleteIndex"]);
}



$query = "Select * from sinhvien";
$result = mysql_query($query);
$number = mysql_num_rows($result);

mysql_close($connect);
//echo "<br> So luong ket qua ".$number;

?>
<FORM name="deleteForm" method="post" action="delete.php">
<H3 align="center">Lựa chọn sinh viên cần xoá</H3>

<TABLE WIDTH = "90%" BORDER = "1" align = "center" margin=20>

<TR class = "TIEUDE">
<TH>Mã số sinh viên</TH>
<TH>Họ tên</TH>
<TH>Giới tính</TH>
<TH>Ngày sinh</TH>
<TH>Quê quán</TH>
<TH>Ngành học</TH>
<TH>Xoá</TH>
</TR>

<?php 


$index = 0;
while ($index < $number) {
  $mssv = mysql_result($result, $index,"mssv");
  $hoten = mysql_result($result, $index,"hoten");
  $gioitinh = mysql_result($result, $index,"gioitinh");
  if ($gioitinh=="0"){
     $gioitinh ="Nữ";
  }
  else {
    $gioitinh = "Nam";
    
  }
  $ngaysinh = mysql_result($result, $index,"ngaysinh");
  $quequan = mysql_result($result, $index,"quequan");
  $nganhhoc = mysql_result($result, $index,"nganhhoc");
	//echo "<br>Shsv:$mssv Hoten:$hoten Ngaysinh: $ngaysinh Quequan: $quequan Nganhhoc: $nganhhoc";
  
  ?>
   <tr CLASS = "ROW">
   <th><p><?php echo $mssv?></p></th>
   <th><p><?php echo $hoten?></p></th>
   <th><p><?php echo $gioitinh?></p></th>
   <th><p><?php echo $ngaysinh?></p></th>
   <th><p><?php echo $quequan?></p></th>
   <th><p><?php echo $nganhhoc?></p></th>
   <TH><button type="submit" name="deleteIndex" value="<?php echo $mssv;?>" onclick="javascript:return checkIfSure();">Delete</button></TH>
  </tr>
  <?php 
  $index++;
}
?>
</TABLE>
</FORM>
     </div>
  </div>
</body>



</html>
